package com.itcam.thread_;

/**
 * Author:Cammy.Wu
 * Date:2024-05-10
 * Description:
 */

public class ThreadMethodDemo05 {
    /*
        线程优先级的方法：(只是能提高某一个线程抢到cpu的概率)
            抢占式调度
            public setPriority(int newPriority):设置线程优先级
            public final int getPriority:获取线程优先级

            优先级 1~10 （默认5）
     */

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <= 200; i++) {
                    System.out.println(Thread.currentThread().getName() + "---" + i);
                }
            }
        }, "线程A：");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <= 200; i++) {
                    System.out.println(Thread.currentThread().getName() + "---" + i);
                }
            }
        }, "线程B：");

        t1.setPriority(1);
        t2.setPriority(10);

        System.out.println(t1.getPriority());
        System.out.println(t2.getPriority());

        t1.start();
        t2.start();

    }
}
